package boot.spring.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author user$
 * @version $Id: ThreadPoolUtil$, v 0.1 2019/12/12$ 21:29$ user$ Exp$
 */
public class ThreadPoolUtil {
    private static volatile ThreadPoolUtil instance;
    private static ExecutorService threadPool;

    public static ThreadPoolUtil getInstance()
    {
        if (instance == null) {
            synchronized (ThreadPoolUtil.class)
            {
                instance = new ThreadPoolUtil();
                threadPool = Executors.newCachedThreadPool();
            }
        }
        return instance;
    }

    public void excute(Runnable runnable)
    {
        threadPool.execute(runnable);
    }

    public void shutdown()
    {
        threadPool.shutdown();
    }

    public boolean isActive()
    {
        if (threadPool.isTerminated()) {
            return false;
        }
        return true;
    }

    /*//方法调用
     ThreadPoolUtil.getInstance().excute(new Runnable()
        {
          public void run()
          {
            //调用执行具体业务
          }
       });
   */


}
